import { Provide} from '@midwayjs/core';
import { Book } from '../../entity/user/book';
import { InjectEntityModel } from '@midwayjs/orm';
import { Repository } from 'typeorm';


@Provide()
export class BookService {

  @InjectEntityModel(Book)
  bookModel:Repository<Book>

  async getAllbook():Promise<Book[]>{
    try{
      const result = await this.bookModel.find()
      return result
    }catch(err){
      console.log("err",err);  
    }
  }
  async takeOrder(id){
    try{
      const info = await this.bookModel.findOne({
        where:{
            id:id
        }
      })
      info.status='1'
      const result = await this.bookModel.save(info)
      return result 
    }catch(err){
      console.log("err",err);  
    }
  }
  
}
